<template>
  <BasicModal v-bind="$attrs" @register="registerModal" destroyOnClose title="编辑" :width="1024" @ok="handleSubmit">
    <BasicForm @register="registerForm" ref="formRef">
    </BasicForm>
  </BasicModal>
</template>

<script lang="ts" setup>
import { ref, computed, unref, reactive } from 'vue';
import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import { VALIDATE_FAILED } from '/@/utils/common/vxeUtils';
import { saveOrUpdate } from "../PsPlanningScheduling.api.ts";
import { psPlanningSchedulingOrderContentFormSchema } from "../PsPlanningScheduling.data.ts";
// Emits声明
const emit = defineEmits(['register', 'success']);
let activeData = reactive({});

//表单配置
const [registerForm, { setProps, resetFields, setFieldsValue, validate }] = useForm({
  labelWidth: 120,
  schemas: psPlanningSchedulingOrderContentFormSchema,
  showActionButtonGroup: false,
  baseColProps: { span: 8 },
});
//表单赋值
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  //重置表单
  await reset();
  setModalProps({ confirmLoading: false});
  // 储存传递进来的数据
  activeData = data;
  //表单赋值
  await setFieldsValue({
    ...data,
  });
});
async function reset() {
  activeData = {};
  await resetFields();
}
//表单提交事件
async function handleSubmit() {
  try {
    const values = Object.assign(activeData,await validate());
    setModalProps({ confirmLoading: true });
    //提交表单
    await saveOrUpdate(values, true);
    //关闭弹窗
    closeModal();
    //刷新列表
    emit('success');
  } finally {
    setModalProps({ confirmLoading: false });
  }
}
</script>

<style lang="less" scoped>
/** 时间和数字输入框样式 */
:deep(.ant-input-number) {
  width: 100%;
}

:deep(.ant-calendar-picker) {
  width: 100%;
}
</style>